//
//  UserCell.m
//  Molian
//
//  Created by 胡津 on 4/6/2015.
//  Copyright (c) 2015年 xiaocan. All rights reserved.
//

#import "UserCell.h"

@implementation UserCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGFloat CellHeight = 60;
        
        //用户头像
        self.userAvatarImg = [[UIImageView alloc]init];
        self.userAvatarImg.frame = CGRectMake(8, (CellHeight-40)/2, 40, 40);
        self.userAvatarImg.layer.masksToBounds = YES;//开启圆角
        [self.userAvatarImg.layer setCornerRadius:4];
        [self.userAvatarImg setContentMode:UIViewContentModeScaleAspectFill];
        self.userAvatarImg.tintColor = [UIColor redColor];
        [self.userAvatarImg setImage:[UIImage imageNamed:@"common_avatar_loading_background"]];
        [self.contentView addSubview:self.userAvatarImg];
        
        
        //用户名字
        self.userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.userAvatarImg.frame)+8, CGRectGetMinY(self.userAvatarImg.frame), DeviceWidth-134, 24)];
        [self labelStyle:self.userNameLabel];
        self.userNameLabel.textColor = RGBA(51, 51, 51, 1);
        self.userNameLabel.font = [UIFont fontWithName:FontName size:16];
        [self.contentView addSubview:self.userNameLabel];
        
        
                self.userSeriesLabel.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255) / 255.0f
                                                                       green:arc4random_uniform(255) / 255.0f
                                                                        blue:arc4random_uniform(255) / 255.0f alpha:1];

        
        //用户年龄
        self.userAgeLabel = [[UIButton alloc]init];
        self.userAgeLabel.frame = CGRectMake(CGRectGetMaxX(self.userAvatarImg.frame)+8, CGRectGetMaxY(self.userAvatarImg.frame)-12, 22, 12);
        [self labelStyle:self.userAgeLabel.titleLabel];
        [self.userAgeLabel.layer setCornerRadius:6];
        self.userAgeLabel.clipsToBounds = YES;
        self.userAgeLabel.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        self.userAgeLabel.contentEdgeInsets = UIEdgeInsetsMake(1, 0, 0, 0);
        [self.userAgeLabel setBackgroundImage:[UIImage imageNamed:@"boy_age"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.userAgeLabel];
        self.userAgeLabel.userInteractionEnabled = NO;
        
        
        //用户系列
        self.userSeriesLabel = [[UIButton alloc]init];
        self.userSeriesLabel.frame = CGRectMake(CGRectGetMaxX(self.userAgeLabel.frame)+4, CGRectGetMaxY(self.userAvatarImg.frame)-12+1, 64, 12);
//        [self.userSeriesLabel setBackgroundImage:[UIImage imageNamed:@"知性暖男系"] forState:UIControlStateNormal];
        [self.userSeriesLabel setTitleColor:RGBA(122, 122, 122, 1) forState:UIControlStateNormal];
        self.userSeriesLabel.titleLabel.font = kFont(10);
        [self.userSeriesLabel setTitle:@"" forState:UIControlStateNormal];
        [self.contentView addSubview:self.userSeriesLabel];
        self.userSeriesLabel.userInteractionEnabled = NO;

        CATransition *trans=[[CATransition alloc]init];
        [trans setType:kCATransitionReveal];
        [trans setSubtype:kCATransitionFromLeft];
        [trans setDuration:0.5];
        [self.layer addAnimation:trans forKey:nil];
        
    }
    return self;
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(UILabel *)labelStyle:(UILabel *)label//统一风格
{
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont fontWithName:FontName size:10];
    return label;
}


@end
